'use strict'
import { QueryInterface, DataTypes } from 'sequelize'
/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface: QueryInterface, Sequelize: typeof DataTypes) {
    await queryInterface.createTable('Orders', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER.UNSIGNED,
      },
      outTradeNo: {
        allowNull: false,
        unique: true,
        type: Sequelize.STRING,
      },
      tradeNo: {
        unique: true,
        type: Sequelize.STRING,
      },
      userId: {
        allowNull: false,
        type: Sequelize.INTEGER.UNSIGNED,
      },
      roleId: {
        allowNull: false,
        type: Sequelize.INTEGER.UNSIGNED,
      },
      subject: {
        allowNull: false,
        type: Sequelize.STRING,
      },
      totalAmount: {
        allowNull: false,
        type: Sequelize.DECIMAL(10, 2).UNSIGNED,
      },
      paymentMethod: {
        type: Sequelize.ENUM,
        values: ['alipay', 'wxpay', 'qqpay', 'tenpay'],
      },
      status: {
        allowNull: false,
        defaultValue: 0,
        type: DataTypes.TINYINT.UNSIGNED,
      },
      durationMonths: {
        allowNull: false,
        defaultValue: 1,
        type: Sequelize.INTEGER.UNSIGNED,
      },
      paidAt: {
        type: Sequelize.DATE,
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE,
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE,
      },
    })
    await queryInterface.addIndex('Orders', {
      fields: ['userId'],
    })
    await queryInterface.addIndex('Orders', {
      fields: ['roleId'],
    })
  },
  async down(queryInterface: QueryInterface, Sequelize: typeof DataTypes) {
    await queryInterface.dropTable('Orders')
  },
}
